package com.smartad.ApplicationServer;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import com.smartad.common.MyConfig;

public class HttpServer extends Thread {

	ServerSocket _socket = null;

	protected void finalize() {
		try {
			if (_socket != null) {
				_socket.close();
				_socket = null;
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void run() {
		
		try {
			_socket = new ServerSocket(MyConfig.getInstance()
					.getHttpPort());
		} catch (IOException e) {
			e.printStackTrace();
		}
		while (true) {
			try {
				Socket inSoc = _socket.accept();
				new HttpWorker(inSoc).start();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}
